home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest way to index thru an array????
- Date: Thu, 11 Jan 1996 13:47:01 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d34p7$kj9@tahko.lpr.carel.fi>
- References: <4d1g3k$o09@solaris.cc.vt.edu>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- Ashutosh Gokhale <ashutosh> wrote:
-
- >Suppose I have an array A[][][] which I declare as
- > double ***A and then assign memory to it using new operator.
- >Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
- >entries of A using
- >for(i=1; i<50; i++)
- > {
- > for(j=1; j<60; j++)
- > {
- > for(k=1; k<70; k++)
- > {
- > A[i][j][k] = <some expression>;
- > }
- > }
- > }
- >But the above way is surely the most time-INEFFICIENT way.
- >Can someone suggest me the MOST time efficient way of indexing through A[][][]?
-
- >Thanks a lot
-
- Try this:
-
- double *p = A;
-
- for (i = 0; i < 50*60*70; i++)
- *p++ = <some expression>;
-
- BTW, array indexes in C/C++ begin at 0, _not_ at 1.
-
- Later,
- AriL
-
- All my opinions are mine and mine alone.
-
-